package com.yonyou.sto.modules.ums.util;

import com.yonyou.sto.domain.InvoiceStatusEnums;
import com.yonyou.sto.modules.ims.model.ImsInvoice;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;

import java.util.HashSet;
import java.util.Set;

public class ImsInvoiceUtil {

    public static String getDjlxName(ImsInvoice imsInvoice){
        return "fp".equals(imsInvoice.getDjlx())?"销售发票":("ys".equals(imsInvoice.getDjlx()) ? "应收单": "内部交易结算单");
    }

    public static String getBillTypeName(Integer billType){
        return billType==3?"增值税普通发票":(billType==4 ? "增值税专用发票": (billType==31?"全电专票":"全电普票"));
    }

    public static String getStatusName(Integer status){
        String statusName = "";
        switch (status){
            case 1:
                statusName="未开票";
                break;
            case 2:
                statusName="开票成功";
                break;
            case 3:
                statusName="开票失败";
                break;
            case 4:
                statusName="部分开票";
                break;
            case 5:
                statusName="开票中";
                break;
            case 6:
                statusName="已作废";
                break;
            case 7:
                statusName="已退回";
                break;
            case 8:
                statusName="已红冲";
                break;
            case 9:
                statusName="申请开票";
                break;
        }
        return statusName;
    }

    public static String[] getNullPropertyNames (Object source) {
        final BeanWrapper src = new BeanWrapperImpl(source);
        java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();

        Set<String> emptyNames = new HashSet<>();
        for(java.beans.PropertyDescriptor pd : pds) {
            Object srcValue = src.getPropertyValue(pd.getName());
            if (srcValue == null) emptyNames.add(pd.getName());
        }
        String[] result = new String[emptyNames.size()];
        return emptyNames.toArray(result);
    }
}
